package org.openqa.selenium.example;

import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

import static org.junit.Assert.*;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleneseTestBase;
import com.thoughtworks.selenium.Selenium;
import com.thoughtworks.selenium.SeleniumException;

public class HtmlUnitExample{
	private Selenium _selenium;
    public HtmlUnitExample() {
    	
    }
    
    public String getResult(){
        WebDriver driver = new HtmlUnitDriver();        
        WebDriver driverF = new FirefoxDriver();
    	_selenium = new WebDriverBackedSelenium(driverF, "http://www.daum.net");
    	
    	try{
    		_selenium.open("/");
	    	_selenium.type("q", "selenium rc");
	    	_selenium.click("btnG");
	    	_selenium.waitForPageToLoad("30000");
	    	
	    	assertTrue(_selenium.isTextPresent("Results * for selenium rc"));
    	}catch(SeleniumException se){
    		
    	}
    	
        
        driver.get("http://blog.daum.net/wigiri");
        if(driver.findElements(By.xpath("//frame[@name='BlogMain']"))!=null){
        	driver.switchTo().frame("BlogMain");        	
        }
        //WebElement element = driver.findElement(By.name("q"));
        //element.sendKeys("Cheese!");
        //element.submit();
        StringBuffer sb = new StringBuffer();
        sb.append("Page title is: " + driver.getTitle());
        
        List<WebElement> linkList = driver.findElements(By.xpath("//div[@id='top_Rmenu']//li"));
        for(WebElement el : linkList){
        	sb.append(el.getTagName()+ ":" + el.getText());
        }
        return sb.toString();
    }
}